<template>
  <div>
   <h1>会员增加页面</h1>
   <table class="table table-bordered">
     <tbody>
      <tr>
        <td align="right">会员账号</td>
        <td><input type="text" v-model="queryInfo.Name"/></td>
      </tr>

      <tr>
        <td align="right">密码</td>
        <td><input type="password" v-model="queryInfo.Pwd"/></td>
      </tr>

      <tr>
        <td align="right">确认密码</td>
        <td><input type="password" v-model="Pwdok"/></td>
      </tr>


      <tr>
        <td align="right">手机号</td>
        <td><input type="text" v-model="queryInfo.Phone"/></td>
      </tr>


      <tr>
        <td align="right">身份证</td>
        <td><input type="text" v-model="queryInfo.Card"/></td>
      </tr>


      <tr>
        <td align="right">生日</td>
        <td><input type="date" v-model="queryInfo.Birthday"/></td>
      </tr>


      <tr>
        <td align="right">性别</td>
        <td><input type="radio" name="sex" v-model="queryInfo.Sex" value="1"/>男<input type="radio" name="sex" v-model="queryInfo.Sex" value="0"/>女</td>
      </tr>


      <tr>
        <td align="right">积分</td>
        <td><input type="text" v-model="queryInfo.Points"/></td>
      </tr>

      <tr>
        <td align="right">余额</td>
        <td><input type="text" v-model="queryInfo.Money"/></td>
      </tr>
      <tr>
        <td align="right">会员等级</td>
        <td>
          <select>
            <option value="">请选择</option>
          </select>
        </td>
      </tr>

      <tr>
        <td align="right"></td>
        <td><input type="button" value="增加" @click="Fn"/></td>
      </tr>
     </tbody>
   </table>
  </div>
  <h1>dfdkjfdjfdjdkf</h1>
</template>

<script setup lang="ts">

import {ref,reactive} from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';
//路由器对象
const router =useRouter();
let queryInfo =reactive({
  "Name": "",
  "Phone": "",
  "Card": "",
  "Birthday": "",
  "Sex": 1,
  "State": 0,
  "Pwd": "",
  "Money": "",
  "Points": "",
  "CreateTime": "",
  "UpdateTime": "",
  "IsDeleted": true
})
let Pwdok=ref('');
let memberLevelist=ref();
const Fn=()=>{
//1.非空+有效验证
if(queryInfo.Name=="")
{
alert("账号不能为空");
return;
}
if(queryInfo.Pwd=="")
{
alert("密码不能为空");
return;
}
if(Pwdok.value=="")
{
alert("确认密码不能为空");
return;
}
if(queryInfo.Pwd!=Pwdok.value)
{
  alert("密码和确认密码不一致");
  return;
}
if(queryInfo.Phone=="")
{
  alert("手机号不能为空");
  return;
}
//是否是正确的手机号
let reg =/^1[3-9]\d{9}$/;
if(reg.test(queryInfo.Phone)==false)
{
alert('手机号不合法');
return;  
}
if(queryInfo.Card=='')
{
  alert('身份证不能为空');
  return;
}
let reg1 =/^\d{17}[0-9Xx]/;
if(reg1.test(queryInfo.Card)==false)
{
  alert('身份证不合法');
  return;
}
if(queryInfo.Birthday=="")
{
alert('生日不能为空');
return;
}
if(queryInfo.Points=="")
{
  alert('积分不能为空');
  return;
}
if(isNaN(Number(queryInfo.Points))==true)
{
  alert('积分只能是数字');
  return;
}
if(queryInfo.Money=="")
{
  alert("余额不能为空");
return;
}
if(isNaN(Number(queryInfo.Money))==true)
{
  alert('余额只能是数字');
  return;
}
//2.发送网络请求将数据添加到数据库
axios({ 
  url:'/api/Member/MemberAdd',
  method:'post',
  data:queryInfo
})
.then((res)=>{
  console.log(res);
  if(res.data==-1)
{
  alert('手机号重复');
  return;
}
if(res.data==-2)
{
  alert('身份证号重复');
  return;
}
router.push("/GereView");
})
.catch((err)=>{
  console.log(err);
});

};
</script>

<style scoped>

</style>